﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Yamfinder.Data;

namespace Yamfinder.Service
{
    public class LexicalService : ILexicalService
    {
        private readonly ILexicalRepository _lexicalRepository;
        private readonly ILexicalQuery _lexicalQuery;

        public LexicalService(ILexicalRepository lexicalRepository, ILexicalQuery lexicalQuery)
        {
            _lexicalRepository = lexicalRepository;
            _lexicalQuery = lexicalQuery;
        }

        public LexicalTable Search(LexicalSearchCriteria criteria)
        {
            //Filter
            var resultsList = _lexicalQuery.ExecuteFilters(criteria.Filters);

            //Put results into table and return
            return new LexicalTable(resultsList, criteria);
        }

        public void Add(LexicalEntry newEntry)
        {
            _lexicalRepository.Insert(newEntry);
        }
    }
}